<?php
header('Content-Type:text/html;charset=utf-8'); 
session_start();
include_once( 'config.php' );
include_once('weibooauth.php');
if( !isset($_SESSION['last_key']) ) exit();
$text = $_POST['text'];
$image=$_POST['image'];
//$image = "http://liang.sinaapp.com/pic.php?ids=1,2,3,4,5,6";
//$imageuri = data_uri($image, 'image/jpg');
//echo $imageuri;
//file_put_contents( SAE_TMP_PATH . '/tmp.jpg' , $imageuri );
//echo file_get_contents( SAE_TMP_PATH . '/tmp.jpg' ); 
$sae = new SaeTClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
//var_dump($sae->upload($text, SAE_TMP_PATH . '/tmp.jpg'));
$sae->upload($text, $image);
function data_uri($file, $mime) {  
    $contents = file_get_contents($file);
    $base64 = base64_encode($contents); 
    return "data:$mime;base64,$base64";
}

?>